/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.gui.utils;

import java.io.IOException;
import java.net.URL;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

/**
 *
 * @author nurhat
 */
public class AtofGuiManifestInfo {

    public String getImplementationVersion() {
        Class clazz = AtofGuiManifestInfo.class;
        String className = clazz.getSimpleName() + ".class";
        String classPath = clazz.getResource(className).toString();
        if (!classPath.startsWith("jar")) {
            // Class not from JAR
            return "-";
        }
        String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1)
                + "/META-INF/MANIFEST.MF";
        try {
            Manifest manifest = new Manifest(new URL(manifestPath).openStream());
            Attributes att = manifest.getMainAttributes();

            return att.getValue("Implementation-Version");

        } catch (IOException ex) {
        }

        return "N/A";
    }

    public String getSpecificationVersion() {
        Class clazz = AtofGuiManifestInfo.class;
        String className = clazz.getSimpleName() + ".class";
        String classPath = clazz.getResource(className).toString();
        if (!classPath.startsWith("jar")) {
            // Class not from JAR
            return "-";
        }
        String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1)
                + "/META-INF/MANIFEST.MF";
        try {
            Manifest manifest = new Manifest(new URL(manifestPath).openStream());
            Attributes att = manifest.getMainAttributes();
            return att.getValue("Specification-Version");

        } catch (IOException ex) {
        }

        return "N/A";
    }
}

